﻿using System;
using System.Threading;
using System.Windows.Threading;
using Greycastle.RUBuildin.View;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace RUBuildin.UnitTests
{
    [TestClass]
    public class BubbleWindowTest
    {
        [TestMethod, TestCategory("IntegrationUI")]
        public void CanLoadWindow()
        {
            UiThread.Run(delegate
                {
                    var window = new BubbleWindow {DataContext = new BubbleWindowViewModel(IntPtr.Zero)};
                    var timer = new Timer(CloseWindow, new object[] { Dispatcher.CurrentDispatcher, window}, 5000, 0);
                    window.Show();
                });
        }

        private void CloseWindow(object state)
        {
            var dispatcher = (Dispatcher) ((object[]) state)[0];
            var window = (BubbleWindow) ((object[]) state)[1];
            dispatcher.InvokeAsync(delegate
                {
                    window.Close();
                    window.Closed += (s, e) => dispatcher.InvokeShutdown();
                });
        }
    }
}
